package com.eddie.interator;

import java.util.Iterator;

/**
 * 具体容器，实现了抽象容器的抽象方法
 * 具体容器中存放具体数据，管理数据，并实现迭代器方法创建自己需要的迭代器并将数据传入，从而返回
 * @author Eddie
 * @date 2022/08/03 22:21
 **/
public class ComputerCollege implements College {

    private Department[] departments;
    //保存当前  对象数组的对象个数
    int numOfDepartments = 0;

    public ComputerCollege() {
        departments = new Department[5];
        addDepartment("Java专业", "Java专业");
        addDepartment("PHP专业", "PHP专业");
        addDepartment("大数据专业", "大数据专业");
    }

    @Override
    public String getName() {
        return "计算机学院";
    }

    @Override
    public void addDepartment(String name, String desc) {
        if (numOfDepartments >= 5) {
            throw new RuntimeException("系已满");
        }
        Department department = new Department(name, desc);
        departments[numOfDepartments++] = department;

    }

    //自己本类是知道自己需要什么迭代器的,
    @Override
    public Iterator<Object> createIterator() {
        return new ComputerCollegeIterator(departments);
    }
}
